<template>
	<u-modal :show="show" @confirm="closed" 
	confirm-text="再等等"
	cancel-text="确定"
	:showCancelButton="true" width="550rpx"
	 @cancel="confirm">
		<view class="contents">
			<view>我已收到货，确定完成交易</view>
		</view>
	</u-modal>
</template>

<script>
	import {
		changeStatus,
		orderPay
	} from 'utils/api/order.js'
	import {
		userIndex
	} from 'utils/api/user.js'
	export default {
		data() {
			return {
				show: false,
				allData: {}
			}
		},
		methods: {
			opens(data) {
				this.allData = data
				this.show = true
			},
			closed() {
				this.show = false
			},
			payOrder(data) {
				if(data) {
					this.allData = data
				}
				uni.showLoading({
					title: '支付中'
				})
				const that = this
				orderPay({id: this.allData.id}).then((res) => {
					uni.hideLoading()
					let {timeStamp,nonceStr,signType,paySign} = res.data;
					uni.requestPayment({
						provider: 'wxpay',    //支付类型-固定值
						timeStamp: timeStamp, // 时间戳（单位：秒）
						nonceStr: nonceStr, // 随机字符串
						package: res.data.package, // 固定值
						signType:signType, //固定值
						paySign: paySign, //签名
						success: function (res) {
							uni.showToast({ title: '支付成功', icon: "none" });
							setTimeout(() => {
								that.$emit('update')
							}, 300)
						},
						fail: function (err) {
							uni.showToast({ title: '支付失败', icon: "none" });
						}
					});
				})
			},
			async confirm() {
				uni.showLoading({
					title: '收货中'
				})
				let userInfo = await userIndex()
				changeStatus({
					status: 4,
					id: this.allData.id
				}).then((res) => {
					this.show = false
					// 未签约
					if(userInfo.contractSignStatus == 1) {
						this.$emit('update')
						this.payOrder()
					} else {
						uni.showToast({ title: '收货成功', icon: "none" });
						setTimeout(() => {
							this.$emit('update')
						}, 500)
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.contents {
	box-sizing: border-box;
	padding: 25upx 0;
	>view {
		font-size: 31upx !important;
		color: #000000;
	}
}
</style>